package com.example.mobile2021606144ywr0406;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private Button btnMainCreate;
    private TextView tvMainTitle;
    private RadioGroup radGUPCarType;
    private RadioButton radBtnMainSaloon;
    private RadioButton radBtnMainMPV;
    private RadioButton radBtnMainSUV;
    private RadioGroup radGupMainLine;
    private RadioButton radBtnMainLine1;
    private RadioButton radBtnMainLine2;
    private RadioButton radBtnMainLine3;
    private RadioButton radBtnMainLine4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        radGUPCarType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int i) {
                RadioButton radioButton=findViewById(i);
                Log.i("RadioButton",radioButton.getText().toString());
            }
        });
        radGupMainLine.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int i) {
                RadioButton radioButton=findViewById(i);
                Log.i("RadioButton",radioButton.getText().toString());
            }
        });
        btnMainCreate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String msg="";
                int carId=radGUPCarType.getCheckedRadioButtonId();
                if(carId !=-1) {
                    msg = ((RadioButton) findViewById(carId)).getText().toString();
                }else{
                    msg="未选车型";
                }
                int lineId=radGupMainLine.getCheckedRadioButtonId();
                if (lineId != -1) {
                    msg += "," + ((RadioButton) findViewById(lineId)).getText().toString();
                }else{
                    msg+=",未选生产区";
                }
                Log.i("点击按钮",msg);
            }
        });
    }

    private void initView() {
        btnMainCreate = (Button) findViewById(R.id.btn_main_create);
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        radGUPCarType = (RadioGroup) findViewById(R.id.radGUP_car_type);
        radBtnMainSaloon = (RadioButton) findViewById(R.id.radBtn_main_saloon);
        radBtnMainMPV = (RadioButton) findViewById(R.id.radBtn_main_MPV);
        radBtnMainSUV = (RadioButton) findViewById(R.id.radBtn_main_SUV);
        radGupMainLine = (RadioGroup) findViewById(R.id.radGup_main_line);
        radBtnMainLine1 = (RadioButton) findViewById(R.id.radBtn_main_line1);
        radBtnMainLine2 = (RadioButton) findViewById(R.id.radBtn_main_line2);
        radBtnMainLine3 = (RadioButton) findViewById(R.id.radBtn_main_line3);
        radBtnMainLine4 = (RadioButton) findViewById(R.id.radBtn_main_line4);
    }
}